import {
	createPinia
} from "pinia" //引入pinia
import {
	createPersistedState
} from 'pinia-plugin-persistedstate' //引入持久化插件
import {
	parse,
	stringify
} from 'zipson' //压缩



const pinia = createPinia() //创建pinia实例
pinia.use(customStorage()) //将插件添加到 pinia 实例上

/**
 * @description 自定义pinia持久化api储存方式为 uni.setStorageSync
 * @returns 
 */
function customStorage() {
	return createPersistedState({
		storage: {
			getItem: uni.getStorageSync,
			setItem: uni.setStorageSync
		},
		//配置压缩加密方式，默认SJON字符串
		// serializer: { 
		// 	deserialize: parse,
		// 	serialize: stringify,
		// }
	})
}

export default pinia //导出pinia用于main.js注册